<?php
/**
 * Pronounceable word test file.
 *
 * Infectamic: browser game (http://infectamic.goldzoneweb.info)
 * Copyright 2011, Loic Chardonnet
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 */

require_once TESTS . 'Facade/Lib/PronounceableWordFacade.php';

/**
 * Class for name generator test.
 */
class PronounceableWordTestCase extends CakeTestCase {
    public function setup() {
        parent::setUp();
    }

    /**
     * Checks the possibility to generate the given names.
     */
    public function testPossibilityToGenerateNames() {
        $namesToGenerate = array(
            'alfie',
            'amelia',
            'charlie',
            'clare',
            'emily',
            'evie',
            'george',
            'grace',
            'harry',
            'jack',
            'james',
            'jessica',
            'joshua',
            'lily',
            'oliver',
            'olivia',
            'ruby',
            'sophie',
            'thomas',
            'william',
        );

        foreach ($namesToGenerate as $nameToGenerate) {
            $this->assertTrue($this->canGenerateName($nameToGenerate));
        }
    }

    /**
     * Checks the possibility to generate the given names without consecutive types.
     */
    function testPossibilityToGenerateNamesWithoutConsecutiveTypes() {
        $namesToGenerate = array(
            'evie',
        );

        foreach ($namesToGenerate as $nameToGenerate) {
            $this->assertTrue($this->canGenerateName($nameToGenerate));
        }
    }

    /**
     * Checks the impossibility to generate the given names.
     */
    function testImpossibilityToGenerateNames() {
        $namesToGenerate = array(
            'sfrusphndste',
            'hm',
            'tharswvuscgyhrqqo',
            'fhcxczkcbvomyvducj',
            'vvdhdybgmbzldnzcykqxi',
            'gjnkn',
            'qrgouhzwvfhsafeq',
            'ncesenoki',
            'akixwyn',
            'hrevoupab',
            'hlaweckra',
            'xwephigwhr',
            'jegohrl',
            'rtiminyzz',
            'cebucrydw',
            'ytegylqube',
            'htiggeclye',
        );

        foreach ($namesToGenerate as $nameToGenerate) {
            $this->assertFalse($this->canGenerateName($nameToGenerate));
        }
    }

    /**
     * Checks the impossibility to generate the given names with consecutive types.
     */
    function testImpossibilityToGenerateNamesWithConsecutiveTypes() {
        $namesToGenerate = array(
            'trr',
            'trrvixiewimm',
            'rmichccul',
            'eneeice',
            'vaxudrr',
            'frusphndste',
        );

        foreach ($namesToGenerate as $nameToGenerate) {
            $this->assertFalse($this->canGenerateName($nameToGenerate));
        }
    }

    /**
     * Checks if it is possible to generate the given name.
     *
     * @param string $name The name
     * @return boolean True on success, or else false
     */
    function canGenerateName($name) {
        $canGenerateName = true;

        $pronounceableWord = new PronounceableWordFacade($name);
        if ($name !== $pronounceableWord->generate()) {
            $canGenerateName = false;
        }

        return $canGenerateName;
    }
}
